package cate.game.role.show;


import cate.common.util.GameResult;
import easy.java.dev.note.NoteClass;
import easy.java.dev.note.NoteField;

@NoteClass("饰品基础")
public abstract class ShowItemBase {

    @NoteField("模板id")
    public int tid;

    @NoteField("激活时间")
    public long activeTime;

    @NoteField("过期时间")
    public long expireTime;


    public ShowItemBase() {
    }

    public ShowItemBase(int tid, long valiedTime) {
        this.tid = tid;
        activeTime = System.currentTimeMillis();
        if (valiedTime < 0) {
            expireTime = -1;
        } else {
            expireTime = activeTime;
            expireTime += valiedTime;
        }
    }

    /** 延长时间 */
    public GameResult<Void> extendTime(long valiedTime) {
        GameResult<Void> r = new GameResult<>();
        if (expireTime == -1) {
            return r.fail("激活失败");
        }
        if (valiedTime > 0) {
            expireTime += valiedTime;
        } else {
            expireTime = -1;
        }
        return r.success();
    }

    /** 判断是否过期 */
    public boolean expired() {
        if (expireTime == -1) {
            return false;
        }
        return expireTime <= System.currentTimeMillis();
    }
}
